package com.smartmedi.ai.controller;

import com.smartmedi.ai.common.BaseResponse;
import com.smartmedi.ai.common.ResultUtils;
import com.smartmedi.ai.domain.dto.TimedFileCollectionDto;
import com.smartmedi.ai.service.TimeFileCollectionService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 定时任务文件采集控制器
 */
@RestController
@RequestMapping("/file/collect")
@Slf4j
@RequiredArgsConstructor
public class TimedFileCollectionControlller {

    private final TimeFileCollectionService timeFileCollectionService;

    @PostMapping("/start")
    public BaseResponse<?> startCollect(@RequestBody TimedFileCollectionDto timedFileCollectionDto) {
        try {
            // 开始采集任务
            String taskId = timeFileCollectionService.startFtpCollection(timedFileCollectionDto);
            return ResultUtils.success(taskId, "采集任务已启动");
        } catch (Exception e) {
            log.error("启动FTP采集任务失败", e);
            return ResultUtils.error(500, "启动FTP采集任务失败：" + e.getMessage());
        }
    }

}
